#!usr/bin/python
# -*- coding:utf-8 -*-
import socket


class SocketDemo:
    def _test_socket(self):
        """
        sd = SocketDemo()
        sd._test_socket()
        """
        host_name = socket.gethostname()
        print 'gethostname结果: ', host_name

        host_ip = socket.gethostbyname(host_name)
        print 'gethostbyname结果: ', host_ip

        print 'http://www.baidu.com - gethostbyname结果: ', socket.gethostbyname('www.baidu.com')
        print 'gethostbyname_ex结果: ', socket.gethostbyname_ex('www.jb51.com')
        print 'gethostbyaddr结果: ', socket.gethostbyaddr('127.0.0.1')
        print 'http - getservbyname结果: ', socket.getservbyname('http', 'tcp')
        print 'telnet - getservbyname结果: ', socket.getservbyname('telnet', 'tcp')

        hostname = socket.inet_aton('127.0.0.1')
        print 'inet_aton结果: ', hostname
        print 'inet_ntoa结果: ', socket.inet_ntoa(hostname)


if __name__ == '__main__':
    sd = SocketDemo()
    sd._test_socket()
